#include <thread>
#include <semaphore>
#include <iostream>

class MyClass {
public:
    MyClass() : sem(0) {}  // 初始化信号量为0

    void sleepThread() {
        std::cout << "Sleep thread waiting...\n";
        sem.acquire();  // 如果信号量为0，这将阻塞线程
        std::cout << "Sleep thread woke up!\n";
    }

    void playThread() {
        std::cout << "Play thread releasing semaphore...\n";
        sem.release();  // 增加信号量的值，如果有线程在等待，它将被唤醒
    }

private:
    std::counting_semaphore<1> sem;  // 信号量
};

int main() {
    MyClass myClass;

    std::thread t1(&MyClass::sleepThread, &myClass);
    std::thread t2(&MyClass::playThread, &myClass);

    t1.join();
    t2.join();

    return 0;
}
